package cn.ithers.blog.dao;

import cn.ithers.blog.pojo.Category;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Author: zhanghuan
 * @date: 2020/9/28 9:55
 * @description:
 */
public interface CategoryDao extends JpaRepository<Category, String>, JpaSpecificationExecutor<Category> {

    Category findOneById(String Id);

    @Modifying
    @Query(nativeQuery = true, value = "UPDATE tb_categories SET status = '0' WHERE id = ?")
    int deleteCategroyByUpdateState(String id);

    @Query(nativeQuery = true, value = "select *from tb_categories where status = ? order by create_time DESC ")
    List<Category> listCategoriesByStatus(String status);


}
